package com.macro.mall.controller;

import com.github.pagehelper.PageInfo;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.e.DataAnalysisKeyEntDTO;
import com.macro.mall.dto.o.DataAnalysisKeyOutDTO;
import com.macro.mall.service.DataAnalysisKeyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dataAnalysis/key")
public class DataAnalysisKeyController {
    @Autowired
    private DataAnalysisKeyService dataAnalysisKeyService;

    @RequestMapping("/list")
    public CommonResult list(@RequestBody DataAnalysisKeyEntDTO dataAnalysisKeyEntDTO){
        PageInfo<DataAnalysisKeyOutDTO> list = dataAnalysisKeyService.list(dataAnalysisKeyEntDTO);
        return CommonResult.success(list);
    }

    @RequestMapping("/get")
    public CommonResult get(@RequestBody DataAnalysisKeyEntDTO dataAnalysisKeyEntDTO){
        return null;
    }

    @RequestMapping("/modify")
    public CommonResult modify(@RequestBody DataAnalysisKeyEntDTO dataAnalysisKeyEntDTO){
        int modify = dataAnalysisKeyService.modify(dataAnalysisKeyEntDTO);
        CommonResult<Object> commonResult = new CommonResult<>();
        if (modify>0){
            commonResult.setCode(200);
            commonResult.setMessage("操作成功！");
        }else {
            commonResult.setCode(500);
            commonResult.setMessage("操作失败！");
        }
        return commonResult;
    }

    @RequestMapping("/setStatus")
    public CommonResult setOn(@RequestBody DataAnalysisKeyEntDTO dataAnalysisKeyEntDTO){
        int modify = dataAnalysisKeyService.modify(dataAnalysisKeyEntDTO);
        CommonResult<Object> commonResult = new CommonResult<>();
        if (modify>0){
            commonResult.setCode(200);
            commonResult.setMessage("操作成功！");
        }else {
            commonResult.setCode(500);
            commonResult.setMessage("操作失败！");
        }
        return commonResult;
    }

    @RequestMapping("/setOff")
    public CommonResult setOff(@RequestBody DataAnalysisKeyEntDTO dataAnalysisKeyEntDTO){
        return null;
    }
}
